package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Lucky;

public class LuckyDAOImpl extends BaseHibernateDAOImpl<Lucky> implements LuckyDAO {

	public Lucky getLuckyByLuckyID(String luckyID) {
		Lucky lucky;
		try {
			lucky = (Lucky) getSession().get(Lucky.class, luckyID);
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return lucky;
	}

	@SuppressWarnings("unchecked")
	public List<Lucky> getAllLucky() {
		List<Lucky> luckys;
		try {
			Query query = getSession().getNamedQuery("AllLuckyQuery");
			luckys = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return luckys;
	}
	
	public Lucky getLuckyByIssueNumber(String issueNumber) {
		Lucky lucky;
		try {
			Query query = getSession().getNamedQuery("LuckyByIssueNumberQuery");
			query.setString("issueNumber", issueNumber);
			lucky = (Lucky) query.uniqueResult();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return lucky;
	}

}
